package mygang.service;

import mygang.dao.AuthenticationDAO;
import mygang.model.User;
import mygang.model.UserWrapper;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 *
 * @author Volodymyr Lavrynovych <volodya.lavrynovych@gmail.com>
 */
@Service("userDetailsService")
public class UserDetailsServiceImpl<D extends AuthenticationDAO> extends AbstractService<D> implements UserDetailsService {
    
    @Override
    public UserWrapper loadUserByUsername(String userName) throws UsernameNotFoundException {
        User user = getDao().findUserByLogin(userName);
        if (user == null) {
            throw new UsernameNotFoundException("user not found");
        }
        
        return new UserWrapper(user);
    }
    
}
